home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Text / Edit / GoldED-Demo / installdata / golded / developer / scanner / examples / autodoc / autodocslow.c < prev   
Encoding:
C/C++ Source or Header  |  1999-12-03  |  4.6 KB  |  204 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for AutoDoc nodes. This version understands more autodoc
  4.   files than the "fast" version because it can find autodoc entries even if
  5.   they do not start with a FF.
  6.  
  7.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  8.   code and no library calls permitted. We have to put string constants into
  9.   the code segment (DICE compiler: option -ms1).
  10.  
  11.   DICE:
  12.  
  13.   dcc autodocslow.c -// -l0 -md -mRR -o golded:etc/scanner/autodocslow
  14.  
  15.   ------------------------------------------------------------------------------
  16. */
  17.  
  18. #include <exec/types.h>
  19.  
  20. ULONG
  21. ScanHandlerGuide(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  22. {
  23.     const char version[] = "$VER: ADocSlow 1.3 (" __COMMODORE_DATE__ ")";
  24.  
  25.     static UWORD inbuffer;
  26.  
  27.     // declaring the following buffer as const puts it into the code chunk
  28.  
  29.     const UBYTE buffer[255];
  30.  
  31.     UBYTE *next;
  32.     UWORD  length;
  33.  
  34.     // buffer length for later use
  35.  
  36.     length = len;
  37.  
  38.     // clear "last result" buffer if we start parsing a new document
  39.  
  40.     if (*line == 0)
  41.  
  42.         inbuffer = 0;
  43.  
  44.     // scan the next line and look for an autodoc entry of the form "...<libname>/<funcname>...<libname>/<funcname>...")
  45.  
  46.     next = *text;
  47.  
  48.     while (len > 1) {
  49.  
  50.         // possible entry found ?
  51.  
  52.         if (*next == '/') {
  53.  
  54.             UWORD keylen;
  55.  
  56.             // skip the "/"
  57.  
  58.             ++next;
  59.  
  60.             --len;
  61.  
  62.             // set (possible) result string
  63.  
  64.             *text = next;
  65.  
  66.             // determine the function name length (everything between the "/" and the next space)
  67.  
  68.             for (keylen = 0; len && (*next != ' ') && (*next != 9); ++next, --len)
  69.  
  70.                 ++keylen;
  71.  
  72.             if (keylen) {
  73.  
  74.                 // search for second occurance of the function name in the same line
  75.  
  76.                 while (len > 1) {
  77.  
  78.                     if (*next == '/') {
  79.  
  80.                         // skip the "/"
  81.  
  82.                         ++next;
  83.  
  84.                         for (len = 0; len <= keylen; ++len) {
  85.  
  86.                             if (len == keylen) {
  87.  
  88.                                 // buffer result
  89.  
  90.                                 buffer[len] = 0;
  91.  
  92.                                 while (len--)
  93.  
  94.                                     buffer[len] = (*text)[len];
  95.  
  96.                                 inbuffer = keylen;
  97.  
  98.                                 // return result (ie. length of function name; function name can be found in *text)
  99.  
  100.                                 return(keylen);
  101.  
  102.                             }
  103.                             else if (next[len] != (*text)[len])
  104.  
  105.                                 break;
  106.                         }
  107.  
  108.                         break;
  109.                     }
  110.                     else {
  111.  
  112.                         ++next;
  113.  
  114.                         --len;
  115.                     }
  116.                 }
  117.             }
  118.  
  119.             // syntax error
  120.  
  121.             return(FALSE);
  122.         }
  123.         else {
  124.  
  125.             ++next;
  126.  
  127.             --len;
  128.         }
  129.     }
  130.  
  131.     // did one of the previous lines produce a result ?
  132.  
  133.     if (inbuffer) {
  134.  
  135.         next = *text;
  136.  
  137.         // look for "alternative version" mentioned in the text
  138.  
  139.         while (length) {
  140.  
  141.             // skip white space
  142.  
  143.             while (length && (*next < 'A')) {
  144.  
  145.                 --length;
  146.  
  147.                 ++next;
  148.             }
  149.  
  150.             // check next word
  151.  
  152.             if (length) {
  153.  
  154.                 UWORD keylen;
  155.  
  156.                 // set (possible) result string
  157.  
  158.                 *text = next;
  159.  
  160.                 // determine length of next word
  161.  
  162.                 for (keylen = 0; length && (*next >= 'A'); ++next) {
  163.  
  164.                     ++keylen;
  165.  
  166.                     --length;
  167.                 }
  168.  
  169.                 // close match found ?
  170.  
  171.                 if (**text == *buffer) {
  172.  
  173.                     // only last letter may differ; eg. DrawBevelBox vs. DrawBevelBoxA
  174.  
  175.                     if ((keylen == (inbuffer + 1)) || (keylen == (inbuffer - 1))) {
  176.  
  177.                         UWORD compare = (keylen < inbuffer) ? keylen : inbuffer;
  178.  
  179.                         while (compare--) {
  180.  
  181.                             if ((*text)[compare] != buffer[compare])
  182.  
  183.                                 break;
  184.  
  185.                             else if (compare == 0) {
  186.  
  187.                                 // stop searching for alternative versions
  188.  
  189.                                 *buffer = 0;
  190.  
  191.                                 // return result
  192.  
  193.                                 return(keylen);
  194.                             }
  195.                         }
  196.                     }
  197.                 }
  198.             }
  199.         }
  200.     }
  201.  
  202.     return(FALSE);
  203. }
  204.